﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetOpenAuth.OpenId.Extensions.ProviderAuthenticationPolicy;
using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
using DotNetOpenAuth.OpenId.RelyingParty;
using OpenIdRelyingPartyWebForms;
using System.Net;
using System.Xml.Serialization;
using WcfServiceLibrary;


namespace _1041326_1041339_1041433.UserPages
{
    public partial class HomePage : System.Web.UI.Page
    {

        String url = "http://localhost:1871/Service.svc";
        protected void Page_Load(object sender, EventArgs e)
        {
            HienThiRSS();
            HienThiTinMuaBan();

        }
        private void HienThiTinMuaBan()
        {
            WebRequest wr = WebRequest.Create(url + "/news/getAll");
            WebResponse wp = wr.GetResponse();
            XmlSerializer serial = new XmlSerializer(typeof(ArrayOfTinTucDTO));
            ArrayOfTinTucDTO ds = (ArrayOfTinTucDTO)serial.Deserialize(wp.GetResponseStream());
            gvTinTuc.DataSource = ds.Items;
            gvTinTuc.DataBind();

        }
        private void HienThiRSS()
        {
            String link1 = "http://vnexpress.net/rss/gl/vi-tinh.rss";
            String link2 = "http://tuoitre.vn/RssFeeds.aspx?ChannelID=67";

            try
            {
                List<CustomSyndicationItem> multiRss1 = RssHelper.Get_RSS(link1);
                this.gvRss1.DataSource = multiRss1;
                this.gvRss1.DataBind();
                List<CustomSyndicationItem> multiRss2 = RssHelper.Get_RSS(link2);
                this.gvRss2.DataSource = multiRss2;
                this.gvRss2.DataBind();
            }
            catch (Exception ex)
            {
                Raise_Msg(ex.Message);
            }
           
        }
        protected void Raise_Msg(string msg)
        {
            lbMessage.Visible = true;
            lbMessage.Text = msg;
          
        }
     

        protected void gvTinTuc_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvTinTuc.PageIndex = e.NewPageIndex;
        }

        protected void gvRss2_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvRss2.PageIndex = e.NewPageIndex;
        }

        protected void gvRss1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

            gvRss1.PageIndex = e.NewPageIndex;
        }
    }

}